package org.luckystrophe.snowtoms.model.impl;

import org.json.JSONException;
import org.json.JSONObject;
import org.luckystrophe.snowtoms.R;
import org.luckystrophe.snowtoms.model.JsonRequestPOST;
import org.luckystrophe.snowtoms.pref.AppPreference_;
import org.luckystrophe.snowtoms.pref.UserPreference_;

import android.content.Context;

import com.googlecode.androidannotations.annotations.EBean;
import com.googlecode.androidannotations.annotations.RootContext;
import com.googlecode.androidannotations.annotations.res.StringRes;
import com.googlecode.androidannotations.annotations.sharedpreferences.Pref;

@EBean
public class RequestInitializeClient extends JsonRequestPOST {

	@RootContext
	Context context;

	@Pref
	UserPreference_ pref;

	@Pref
	AppPreference_ appPref;

	@StringRes(R.string.api_method_initializeClient)
	String apiMethod;

	@Override
	public JSONObject getBody() throws JSONException {
		JSONObject jo = new JSONObject();
		JSONObject params = new JSONObject();

		jo.put("method", apiMethod);
		jo.put("params", params);
		return jo;
	}

	public void parseResultJson(JSONObject resultJson) throws JSONException {
		JSONObject params = resultJson.getJSONObject("params");
		long lastMsgId = params.getLong("lastMsgId");
		appPref.lastMsgId().put(lastMsgId);
	}
}
